package com.practice.java8.stream;

import java.util.ArrayList;
import java.util.List;

public class MatchMain {

	public static void main(String[] args) {
		match();
	}
	
	public static void match() {
		List<Person> persons = new ArrayList<>();
		persons.add(new Person(1, 10));
		persons.add(new Person(2, 21));
		persons.add(new Person(3, 34));
		persons.add(new Person(4, 6));
		persons.add(new Person(5, 55));
		boolean isAllAdult = persons.stream().
			allMatch(p -> p.getAge() > 18);
		System.out.println("All are adult? " + isAllAdult);
		boolean isThereAnyChild = persons.stream().
			anyMatch(p -> p.getAge() < 12);
		System.out.println("Any child? " + isThereAnyChild);
		boolean isNoneAdult = persons.stream().
			noneMatch(p -> p.getAge() > 18);
		System.out.println("None is adult? " + isNoneAdult);
	}
	
	private static class Person {

		private Integer number;
		
		private Integer age;

		public Person(Integer number, Integer age) {
			this.number = number;
			this.age = age;
		}

		public Integer getNumber() {
			System.out.println(number);
			return number;
		}

		public Integer getAge() {
			System.out.println(age);
			return age;
		}
		
	}

}
